package com.meessiom.train.crm.order.controller;

import com.meessiom.train.crm.order.model.OrderInfo;
import com.meessiom.train.crm.order.service.OrderInfoService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@CrossOrigin("*")
@RestController
@RequestMapping("/api/v1/orders")
@Slf4j


public class OrderController {

    @Autowired
    private OrderInfoService orderInfoService;
    @PostMapping
    public ResponseEntity<OrderInfo> createOrder(@RequestBody OrderInfo orderInfo) {
        OrderInfo savedOrder = orderInfoService.save(orderInfo);
        return ResponseEntity.ok(savedOrder);
    }



    @GetMapping
    public List<OrderInfo> getAllOrders (){
        return orderInfoService.getAllOrders();
    }

    @DeleteMapping("{id}")  // 使用 DELETE 方法
    public ResponseEntity<HttpStatus> deleteOrder(@PathVariable long id) {
        orderInfoService.delete(id);
        return ResponseEntity.ok(HttpStatus.NO_CONTENT);  // 返回 204
    }
}
